package logic

import (
	"context"
	"go.uber.org/zap"
	"smart-health-platforms/pkg"
	"user_srv/internal/dao"
	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetBitmapContinuousDaysLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetBitmapContinuousDaysLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetBitmapContinuousDaysLogic {
	return &GetBitmapContinuousDaysLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetBitmapContinuousDaysLogic) GetBitmapContinuousDays(in *user.GetBitmapContinuousDaysRequest) (*user.GetBitmapContinuousDaysResponse, error) {
	// 调用 dao 层的 GetBitmapContinuousDays 方法
	days, err := dao.GetBitmapContinuousDays(in.UserId)
	if err != nil {
		pkg.Error("获取用户连续签到天数失败", zap.Error(err))
		return nil, err
	}

	return &user.GetBitmapContinuousDaysResponse{
		Days: int32(days),
	}, nil
}
